//
//  NewInformationViewModel.m
//  GLGW_Shoping
//
//  Created by whx on 2018/12/13.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "NewInformationViewModel.h"
#import "CirclrDetailHeaderView.h"
#import "NewInformationBottomView.h"
#import "NoDataFootTableViewHeaderFooterView.h"
#import "NewInformationTableViewCell.h"
#import "NewInformationOnlyCommentsTableViewCell.h"

@interface NewInformationViewModel ()<UITableViewDelegate, UITableViewDataSource>
{
    UITableView *selfTableView;
    UIView *selfView;
    CirclrDetailHeaderView *headerView;
    NewInformationBottomView *bottomView;
}

@end

@implementation NewInformationViewModel

- (instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView
{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        
        tableView.height -= kHeightProportion_In_iPhoneTriploid(30);
        selfTableView = tableView;
        selfTableView.delegate = self;
        selfTableView.dataSource = self;
        selfTableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        selfTableView.sectionFooterHeight = 0;
        selfTableView = tableView;
        [selfTableView registerClass:[CirclrDetailHeaderView class] forHeaderFooterViewReuseIdentifier:@"CirclrDetailHeaderView"];
        [selfTableView registerClass:[NoDataFootTableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"NoDataFootTableViewHeaderFooterView"];
        
        [superView addSubview:tableView];
        selfView = superView;
        
        bottomView = [[NewInformationBottomView alloc] initWithInSuperView:superView];
        bottomView.BlockReply = ^(GLGWButton * _Nullable ReplyBtn) {
            DLog(@"回复");
        };
    }
    return self;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return kHeightProportion_In_iPhoneTriploid(10);
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return kHeightProportion_In_iPhoneTriploid(39);
    }
    return kHeightProportion_In_iPhoneTriploid(10);
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    NoDataFootTableViewHeaderFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"NoDataFootTableViewHeaderFooterView"];
    return footerView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    return 9;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    kWeakSelf(self);
    if (indexPath.section == 0) {
        NewInformationTableViewCell *cell = [NewInformationTableViewCell cellWithTableView:tableView];
        cell.BlockLikeBtn = ^(GLGWButton *btn) {
            [weakself likeTopBtn:btn];
        };
        return cell;
    }
    NewInformationOnlyCommentsTableViewCell *celll = [NewInformationOnlyCommentsTableViewCell cellWithTableView:tableView];
    celll.BlockLike = ^(GLGWButton * _Nullable likeBtn) {
        [weakself likeBtn:likeBtn];
    };
    return celll;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        CirclrDetailHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"CirclrDetailHeaderView"];
        headerView.desStr = @"全部38条评论";
        return headerView;
    }
    return nil;
}

- (void)likeBtn:(GLGWButton *)btn
{
    // 点赞
    if (self.BlockLike) {
        self.BlockLike(btn);
    }
}

// 顶部的文章点赞
- (void)likeTopBtn:(GLGWButton *)sender
{
    
}

@end
